<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css"/>
		<script type="text/javascript" src="../js/layui/layui.js"></script>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/makePY.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
	</style>
	
	<body>
		<div class="layui-container">
			<div  class="layui-row">
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 20px;">
					<fieldset class="layui-elem-field" style="margin-top: 20px;">
					  <legend>建立团队</legend>
					  <div class="layui-form">
					  	<form  action="" method="" class="layui-form ">
					  		
					  		<div class="layui-form" style="margin: 20px;">
					  			<label class="layui-form-label">团队名称</label>
					  			<div class="layui-input-block">
					  				<input type="text" name="team_name" class="layui-input" lay-verify="required" lay-reqtext="团队名不能为空" placeholder="医疗机构名称" autocomplete="off"  />
					  			</div>
					  		</div>
								
								<div class="layui-form" style="margin: 20px;">
									<div class="layui-form-item" id="area-picker">
									    <div class="layui-form-label">机构地址</div>
									    <div class="layui-input-inline" style="width: 130px;">
									        <select name="province" class="province-selector" data-value="" lay-filter="province-1">
									            <option value="">请选择省</option>
									        </select>
									    </div>
									    <div class="layui-input-inline" style="width: 130px;">
									        <select name="city" class="city-selector" data-value="" lay-filter="city-1">
									            <option value="">请选择市</option>
									        </select>
									    </div>
									    <div class="layui-input-inline" style="width: 125px;">
									        <select name="county" class="county-selector" data-value="" lay-filter="county-1">
									            <option value="">请选择区</option>
									        </select>
									    </div>
									</div>
								</div>
					  		
					  		<div class="layui-form" style="margin: 20px;">
					  			<label class="layui-form-label">团队队长</label>
					  			<div class="layui-input-block">
					  				<input type="text" name="team_leader" class="layui-input" lay-verify="required" lay-reqtext="负责人姓名不能为空" placeholder="张三" autocomplete="off"  />
					  			</div>
							</div>
							
							<div class="layui-form" style="margin: 20px;">
								<label class="layui-form-label">电话</label>
								<div class="layui-input-block">
									<input type="tel" id="phone" name="team_leader_phone" class="layui-input" lay-verify="required|phone" lay-reqtext="电话不能为空" placeholder="机构电话或队长电话(不支持固话)" autocomplete="off"  />
								</div>
							</div>
							
							<div class="layui-form" style="margin: 20px;">
								<label class="layui-form-label">团队介绍</label>
								<div class="layui-input-block">
									<textarea placeholder="" name="team_introduce" class="layui-textarea"></textarea>
								</div>
							</div>
					  		<!-- submit -->
					  		<div class="layui-form" style="margin: 20px;">
					  			<div class="layui-input-block">
					  				<input type="submit"  class="layui-btn layui-btn-normal"  lay-submit lay-filter="submit_button" style="width: 100% ;" value="创建团队"/>
					  			</div>
					  		</div>
					  	</form>
					  </div>
					</fieldset>
		
				</div>
			</div>
		</div>
		
		<script src="../js/mods/layarea.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var address;
			layui.config({
			    base: '../js/mods/'
			    , version: '1.0'
			});
			
			layui.use(['layer', 'form', 'element','layarea'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element,
					layarea = layui.layarea;
					
				form.render();
				
				layarea.render({
				    elem: '#area-picker',
				    change: function (res) {
				        //选择结果
								address = res;
				        console.log(res);
				    }
				});
				
				form.verify({
					team_name_ver : [/^[\u4E00-\u9fFA5]{6,12}$/,'团队名称在6到12位,且不能出现空格'],
				});
				
				form.on("submit(submit_button)", function (data) {
					
					var k = JSON.stringify({
							team_name : data.field.team_name,//团队名称
							team_leader : data.field.team_leader,//团队负责人姓名
							team_leader_phone :  data.field.team_leader_phone,//团队长电话
							team_address : data.field.province+'-'+data.field.city+'-'+data.field.county,
							team_introduce : data.field.team_introduce,
							establish_phone : localStorage.getItem("FDSMS"),//团队建立人电话
							identify : 'doctor',//身份
							unique_code :Date.parse(new Date())+getPy(data.field.team_name).toString(),//生成的医疗机构的唯一编码(时间戳+拼音首字母)
						});
						console.log(k);
						
					$.ajax({
						url:'http://123.56.67.48:8080/createTeam',
						method:'POST',
						contentType:'application/json',
						data:k,
						success:function(res){
							console.log(res);
							if(JSON.parse(res).code == 1){
								alert("创建团队成功");
								window.location.reload();  
							}
							if(JSON.parse(res).code == 0){
								alert("你没有权限创建团队或你已经创建了团队");
							}
						},              
						error:function (res) {
							console.log("团队创建失败"+res); 
						}           
					}); 	
					return false;
				});
				
				
				
			});
		</script>
	</body>
</html>